
#include "Cart.h"

Cart::Cart(std::string name, double price_per)
    : Commodity(std::move(name), price_per)
    , comm_set_(CommSet())
{

}

Cart::~Cart()
{
  for (auto& c : comm_set_)
    delete c;
  comm_set_.clear();
}

void Cart::Add(Commodity* c)
{
  if (c != this)
    comm_set_.insert(c);
}

void Cart::Remove(Commodity* c)
{
  comm_set_.erase(c);
}

double Cart::CheckOut()
{
  double sum_p = price_per_;
  printf("%-20s|%-10.2f|%-10.2f|%-10.2f\n", name_.c_str(), 1.0f, price_per_, price_per_);
  for (auto& c : comm_set_) {
    sum_p += c->CheckOut();
  }
  return sum_p;
}
